package org.sauceggplant.item.man.dao;

import com.alibaba.fastjson2.JSON;
import org.sauceggplant.item.man.dto.SqlDto;
import org.sauceggplant.item.man.service.SqlExecuteService;
import org.sauceggplant.item.man.service.impl.SqlExecuteServiceImpl;
import org.slf4j.Logger;

import java.sql.SQLException;

public abstract class AbstractDao {

    protected SqlExecuteService sqlExecuteService = new SqlExecuteServiceImpl();

    abstract protected Logger getLogger();

    public int insert(SqlDto sqlDto) throws SQLException {
        getLogger().info(JSON.toJSONString(sqlDto));
        return sqlExecuteService.execute(sqlDto);
    }

    public int update(SqlDto sqlDto) throws SQLException {
        getLogger().info(JSON.toJSONString(sqlDto));
        return sqlExecuteService.execute(sqlDto);
    }

    public int delete(SqlDto sqlDto) throws SQLException {
        getLogger().info(JSON.toJSONString(sqlDto));
        return sqlExecuteService.execute(sqlDto);
    }
}
